import 'package:flutter/material.dart';

class TextFieldDemo extends StatefulWidget {
  const TextFieldDemo({Key key}) : super(key: key);
  @override
  _TextFieldDemoState createState() => _TextFieldDemoState();
}

class _TextFieldDemoState extends State<TextFieldDemo> {
  String textStr = 'textFieid默认的文字';
  TextEditingController c = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TextFieidDemo'),
      ),
      body: Container(
        child: Column(
          children: [
            Text('data'),

            ///默认光标显示在后面
            TextField(
              controller: TextEditingController.fromValue(
                TextEditingValue(
                  text: textStr,
                  selection: TextSelection.fromPosition(
                    TextPosition(
                        affinity: TextAffinity.downstream,
                        offset: textStr.length),
                  ),
                ),
              ),
            ),

            ///光标在前
            TextField(
              controller: c,
              decoration: InputDecoration(
                border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                    borderSide: BorderSide.none),
              ),
            )
          ],
        ),
      ),
    );
  }
}
